package com.qcby.controller;

import com.qcby.common.Result;
import com.qcby.form.TProductCategoryForm;
import com.qcby.form.TProductCategoryListForm;
import com.qcby.service.TProductCategoryService;
import com.qcby.vo.PageVO;
import com.qcby.vo.TProductCategoryVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@RequestMapping("/product-category")
public class TProductCategoryController {

    @Autowired
    private TProductCategoryService categoryService;

    /**
     * 分类列表
     */
    @GetMapping("/list")
    public Result<PageVO<TProductCategoryVO>> list(@Valid TProductCategoryListForm form) {
        PageVO<TProductCategoryVO> pageVO = categoryService.getCategoryList(form);
        return Result.success(pageVO);
    }

    /**
     * 添加分类
     */
    @PostMapping
    public Result add(@RequestBody @Valid TProductCategoryForm form) {
        categoryService.addCategory(form);
        return Result.success();
    }

    /**
     * 修改分类
     */
    @PutMapping("/{id}")
    public Result update(@PathVariable("id") Integer id, @RequestBody @Valid TProductCategoryForm form) {
        categoryService.updateCategory(id, form);
        return Result.success();
    }

    /**
     * 删除分类
     */
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable("id") Integer id) {
        categoryService.deleteCategory(id);
        return Result.success();
    }
} 